package com.kim.nidoya.net.business;

import java.io.IOException;
import java.io.InputStream;

import android.util.Log;

import com.kim.net.NetCallback;
import com.kim.net.NetEntity;
import com.kim.nidoya.utils.Utils;

public class NetCallbackImplGetBase implements NetCallback {

	public interface NotifyGet {
		void notifyNetCallback(int httpResponseCode, String result);

		void notifyError(int httpResponseCode, String errorMsg);
	}

	NotifyGet notifyGet;

	public NetCallbackImplGetBase(NotifyGet notifyGet) {
		super();
		this.notifyGet = notifyGet;
	}

	@Override
	public void onSuccess(int httpResponseCode, InputStream inputStream,
			NetEntity netEntity, boolean gzip) {
		String result;
		try {
			result = Utils.convertInputStream2String(inputStream, gzip);
			Log.d("NetCallbackImplGetBase", "resultInStr:" + result);
			if(netEntity != null){
				netEntity.receiveData = result;
			}
			notifyGet.notifyNetCallback(httpResponseCode, result);
		} catch (IOException e) {
			e.printStackTrace();
			notifyGet.notifyError(httpResponseCode, e.getMessage());
		}
	}

	@Override
	public void onError(int httpResponseCode, String errorMsg) {
		notifyGet.notifyError(httpResponseCode, errorMsg);
	}

	@Override
	public void onOtherResponseCode(int httpResponseCode,
			InputStream inputStream, NetEntity netEntity, boolean gzip) {
		String result;
		try {
			result = Utils.convertInputStream2String(inputStream, gzip);
			Log.d("NetCallbackImplGetBase", "resultInStr:" + result);
			notifyGet.notifyNetCallback(httpResponseCode, result);
		} catch (IOException e) {
			e.printStackTrace();
			notifyGet.notifyError(httpResponseCode, e.getMessage());
		}
	}

}
